<%@ page language="java"
         import="com.ruohi.manage.DBType,com.ruohi.manage.PoolManager,com.ruohi.manage.Tools,com.ruohi.util.common.*,com.ruohi.util.dbutil.DBHelper,org.json.JSONObject"
         pageEncoding="UTF-8" %>
<%@page import="java.sql.Connection" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="java.util.*" %>
<%
	Connection connection = null;
	Connection connection2 = null;
	DBHelper dbHelper = DBHelper.getInstance();
	Map model = new HashMap();
	Map categorys = new TreeMap();
	String tableName = "gift_product";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	Map adminInfo = (Map)session.getAttribute("adminInfo");
	LinkedHashMap is_cusMap = new LinkedHashMap();
	is_cusMap.put("0", "否");
	is_cusMap.put("1", "是");
	LinkedHashMap is_packageMap = new LinkedHashMap();
	is_packageMap.put("0", "否");
	is_packageMap.put("1", "是");
	LinkedHashMap isMap = new LinkedHashMap();
	isMap.put("1", "是");
	isMap.put("0", "否");
	
	
	
	
	List<Map> prosupplierList = null;	
	try{
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum("106013"));
		connection2 = PoolManager.getConnection(DBType.getDBTypeByEnum("106010"));
		String id = CommonString.getFormatPara(request.getParameter("id"));
		if(null!=id&&!"".equals(id)){
			model = dbHelper.getMap(" select * from "+tableName+" where uuid = ? ",new Object [] {id} , connection);
		}
		if("".equals(channelUUID)&&null!=model){
			channelUUID = (String)model.get("channel_uuid");
		}
		
		String no = CommonString.getFormatPara(model.get("no"));
		if(no.equals("")){
			no = CommonDate.getToday("yyyyMMddHHmmss")+(int)(Math.random()*1000);
		}
		
		List<Map> supplierList = (ArrayList)application.getAttribute("giftSupplierList");
		List<Map> brandsList = (ArrayList)application.getAttribute("giftBrandList");
		//产品类别
		Map categoryMap = new TreeMap();
		List<Map> categoryList = (List)application.getAttribute("giftCategoryList");
		String n = "";
		String name = "";
		if(categoryList != null){
			for(Map m : categoryList){
				n = (String)m.get("no");
				name = (String)m.get("name");
				name = CommonForm.getHtmlSpaceByString((String)m.get("parent_no"))+name;
				categoryMap.put(n,name);
			}
		}
		//prc类别
		Map cateMap = new TreeMap();
		String sql="select no,name,parent_no from gift_store_category ";
		List<Map> cateList =dbHelper.getMapList(sql,connection);
		String nn= "";
		String names = "";
		if(cateList != null){
			for(Map m : cateList){
				nn = (String)m.get("no");
				names = (String)m.get("name");
				names = CommonForm.getHtmlSpaceByString((String)m.get("parent_no"))+names;
				cateMap.put(nn,names);
			}
		}
		nn = CommonString.getFormatPara(model.get("no"));
		if("".equals(nn)){
			nn = Tools.getNo("0","gift_store_category","106013");
		}
		//该类别下的参数
		String category = CommonString.getFormatPara(model.get("category"));
		List<Map> list = Tools.getCategoryParam(category,"106013");//获得设置为商品网的枚举
		
		//从图
		List<Map> images = dbHelper.getMapList(" select * from gift_sub_image where parent_id = ? order by order_no desc , id asc ",new Object [] {no},connection);
		//图片数量
		int imgCount = 0;
		if(images != null){
			imgCount = images.size();
		}
		//主图
		String mainImageName = CommonString.getFormatPara(model.get("img"));
		String msg = "";
		
		String resDomain = Env.getInstance().getProperty("img_domain");
		
		//推荐月份
		Map enumMap202= (Map)CommonApplication.getEnumChildren("202",application);
		
		//合伙人提点
		double crown_partner_point = 0.00;
		double diamond_partner_point = 0.00;
		double gold_partner_point = 0.00;
		double junior_member_point = 0.01;
		String partner_sql = " select * from service_common_enum where parent_no='201' order by id ";
		List partner_enumList = dbHelper.getMapList(partner_sql, connection2);
		if(partner_enumList!=null){
			for (int i = 0; i < partner_enumList.size(); i++) {
				Map info = (Map)partner_enumList.get(i);
				if(info.get("no").equals("201001")){
					gold_partner_point = CommonString.getFormatDouble(info.get("val"));
				}else if(info.get("no").equals("201002")){
					diamond_partner_point = CommonString.getFormatDouble(info.get("val"));
				}else if(info.get("no").equals("201003")){
					crown_partner_point = CommonString.getFormatDouble(info.get("val"));
				}
			}
		}
		
		//取出规格参数信息
		Map paramKeyMap = new TreeMap();
		Map paramKeyMarketPirceMap = new TreeMap();
		Map paramKeySalePirceMap = new TreeMap();
		Map paramKeyStoreMap = new TreeMap();
		String paramKeySql="select no,market_price,sale_price,store from gift_product_param_key where product_no='"+no+"' ";
		List<Map> paramKeyList =dbHelper.getMapList(paramKeySql,connection);
		if(paramKeyList != null){
			for(Map m : paramKeyList){
				String temp_no = (String)m.get("no");
				String temp_market_price = (String)m.get("market_price");
				String temp_sale_price = (String)m.get("sale_price");
				String temp_store = (String)m.get("store").toString();
				paramKeyMap.put(no,temp_no);
				paramKeyMarketPirceMap.put(temp_no,temp_market_price);
				paramKeySalePirceMap.put(temp_no,temp_sale_price);
				paramKeyStoreMap.put(temp_no,temp_store);
			}
		}
		JSONObject paramKeyMapJson = new JSONObject(paramKeyMap);
		JSONObject paramKeyMarketPirceMapJson = new JSONObject(paramKeyMarketPirceMap);
		JSONObject paramKeySalePirceMapJson = new JSONObject(paramKeySalePirceMap);
		JSONObject paramKeyStoreMapJson = new JSONObject(paramKeyStoreMap);
		
		 DecimalFormat df = new DecimalFormat("#.00");  
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=Env.getInstance().getProperty("project_name") %></title>
<link rel="stylesheet" type="text/css" href="/plugin/other/highslide/highslide.css" />
<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/plugin/area/city/citys.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/editor/ueditor/editor_all_min.js"></script>
<link rel="stylesheet" type="text/css" href="/plugin/editor/ueditor/themes/default/ueditor.css"/>
<style type="text/css">
.shade {
	filter: alpha(opacity=30);
	-moz-opacity: 0.3;
	-khtml-opacity: 0.3;
	opacity: 0.3;
	background-color: #fff;
	position: relative;
	width: 130px;
	height: 135px;
	z-index: 4;
	display: none;
}
.blue {
	border: 1px solid blue;
}
.ccc {
	border: 1px solid #ccc;
}
.toobar {
	position: absolute;
	bottom: 0px;
	height: 20px;
	width: 130px;
	border-top: 1px solid #ccc;
}
.single_img {
	border: 1px solid #ccc;
	width: 130px;
	height: 135px;
	float: left;
	margin: 10px 0 10px 10px;
	display: inline;
	position: relative;
	cursor: pointer;
	overflow: hidden;
}
.single_img .show_img {
	position: absolute;
	bottom: 20px;
}
.formRight {
	text-align: left;
}
</style>
</head>

<body style="margin: 0;padding: 0; overflow-y:auto; *overflow-y:hidden;">
<form name="theform" id="theform" action="/backend/action/crud.jsp?enumNo=106013">
  <div class="formDiv" style="position:relative; text-align:left;">
    <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">基础信息</span> </div>
    <div class="formLeft"><span style="color:#F00">* </span>商品名称</div>
    <div class="formRight" style="width:190px">
      <input type="text" dataType="Require" msg="请输入商品名称" class="jr_text" name="zd_name" id="zd_name" value="<%=CommonString.getFormatPara(model.get("name")) %>" maxlength="100"/>
    </div>
    <div class="formLeft"><span style="color:#F00">* </span>商品编号(自动)</div>
    <div class="formRight" style="width:190px">
      <input type="text" name="zd_no" class="jr_text" readonly="readonly" id="zd_no" value="<%=no %>"/>
    </div>
    <div style="clear:left;"></div>
    <div class="formLeft"><span style="color:#F00">* </span>类别</div>
    <div class="formRight" style="width:190px">
        <select class="jr_select" id="zd_category" name="zd_category" dataType="Require" msg="请选择类别"
                onchange="showParam(this.options[this.selectedIndex].value);">
        <option value="">-请选择类别-</option>
        <%=CommonForm.createSelect(categoryMap, CommonString.getFormatPara(model.get("category"))) %>
      </select>
    </div>
    <div class="formLeft">品牌</div>
    <div class="formRight" style="width:190px">
      <select class="jr_select" id="zd_brand" name="zd_brand">
        <option value="">-请选择品牌-</option>
        <%if(brandsList != null){for(Map m : brandsList){%>
        <option value="<%=m.get("no")%>" <%if(CommonString.getFormatPara(model.get("brand")).equals(m.get("no").toString())){%> selected="selected"<%}%>><%=CnToFullSpell.getFirstSpell(CommonString.getFormatPara(m.get("name"))).length()>=1?CnToFullSpell.getFirstSpell(CommonString.getFormatPara(m.get("name"))).substring(0,1):""%>-<%=CommonString.getFormatPara(m.get("name"))%></option>
        <%}}%>
      </select>
    </div>
    <div style="clear:left;"></div>
      <div class="formLeft">供应商</div>
      <div class="formRight" style="width:190px">
          <select class="jr_select" id="zd_supplier" name="zd_supplier">
              <option value="">-请选择供应商-</option>
              <%
                  if (supplierList != null) {
                      for (Map m : supplierList) {
              %>
              <option value="<%=m.get("no")%>" <%if (CommonString.getFormatPara ( model.get ( "supplier" ) ).equals ( m.get ( "no" ).toString () )) {%>
                      selected="selected"<%}%>><%=CnToFullSpell.getFirstSpell ( CommonString.getFormatPara ( m.get ( "name" ) ) ).length () >= 1 ? CnToFullSpell.getFirstSpell ( CommonString.getFormatPara ( m.get ( "name" ) ) ).substring ( 0, 1 ) : ""%>
                  -<%=CommonString.getFormatPara ( m.get ( "name" ) )%>
              </option>
              <%
                      }
                  }
              %>
          </select>
      </div>
      <div class="formLeft">库存量</div>
      <div class="formRight" style="width:190px">
          <input type="text" class="jr_text" name="zd_storage" id="zd_storage"
                 value="<%=CommonString.getFormatPara(model.get("storage")) %>" maxlength="50"/>
      </div>
      <%--<div class="formLeft">库存预警线</div>--%>
      <%--<div class="formRight" style="width:190px">--%>
      <%--<input type="text" class="jr_text" name="zd_storage_warning" id="zd_storage_warning" value="<%=CommonString.getFormatPara(model.get("storage_warning")) %>" maxlength="50"/>--%>
      <%--</div>--%>
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft"><span style="color:#F00">* </span>市场价</div>--%>
      <%--<div class="formRight" style="width:190px">--%>
      <%--<input type="text" class="jr_text" name="zd_price" id="zd_price" value="<%=CommonString.getFormatPara(model.get("price")) %>" maxlength="50" dataType="Require" msg="请输入参考价" />--%>
      <%--</div>--%>
      <%--<div class="formLeft"><span style="color:#F00">* </span>销售价</div>--%>
      <%--<div class="formRight" style="width:190px">--%>
      <%--<input type="text" class="jr_text" name="zd_price_promotion" id="zd_price_promotion" onkeyup="countPartnerPayment()" value="<%=CommonString.getFormatPara(model.get("price_promotion")) %>" maxlength="50" dataType="Require" msg="请输入促销价" />--%>
      <%--</div>--%>
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft"><span style="color:#F00">* </span>成本价</div>--%>
      <%--<div class="formRight" style="width:190px; text-align:left;">--%>
      <%--<input type="text" class="jr_text" style="width:90%;" name="zd_price_cost" id="zd_price_cost" value="<%=CommonString.getFormatPara(model.get("price_cost")).equals("")?"0.00":CommonString.getFormatPara(model.get("price_cost")) %>" maxlength="50"  dataType="Require" msg="请输入参考价"/>--%>
      <%--元 </div>--%>
      <%--<div style="clear:left;"></div>--%>
      <div style="clear:left;"></div>
      <div class="formLeft"><span style="color:#F00">* </span>普通价</div>
      <div class="formRight" style="width:190px">
          <input type="text" class="jr_text" name="zd_price_204001" id="zd_price_204001"
                 value="<%=CommonString.getFormatPara(model.get("price_204001")).equals("")?"0.00":CommonString.getFormatPara(model.get("price_204001")) %>"
                 maxlength="50" dataType="Require" msg="请输入普通价"/>
      </div>
      <div class="formLeft"><span style="color:#F00">* </span>会员价</div>
      <div class="formRight" style="width:190px">
          <input type="text" class="jr_text" name="zd_price_204002" id="zd_price_204002"
                 value="<%=CommonString.getFormatPara(model.get("price_204002")).equals("")?"0.00":CommonString.getFormatPara(model.get("price_204002")) %>"
                 maxlength="50" dataType="Require" msg="请输入会员价"/>
      </div>
      <div style="clear:left;"></div>
    <div class="formLeft"><span style="color:#F00">* </span>重量(带包装)</div>
    <div class="formRight" style="width:190px; text-align:left;">
      <input type="text" class="jr_text" name="zd_weight" id="zd_weight" style="width:80px;" value="<%=CommonString.getFormatPara(model.get("weight")).equals("")?"0.0":CommonString.getFormatPara(model.get("weight")) %>" maxlength="50"  dataType="Require" msg="请输入商品重量" />
      KG </div>
    <div class="formLeft"><span style="color:#F00">* </span>是否包邮</div>
    <div class="formRight" style="width:190px; text-align:left;"> <%=CommonForm.createRadio(isMap, CommonString.getFormatInt(model.get("is_free_ship")).toString(), "zd_is_free_ship") %> </div>
    <div style="clear:left;"></div>
    <div class="formLeft"><span style="color:#F00">* </span>最小购买数量</div>
    <div class="formRight" style="width:100px;">
      <input type="text" class="jr_text" name="zd_min_buy_count" id="zd_min_buy_count" style="width:80px;" value="<%=CommonString.getFormatInt(model.get("min_buy_count"))==0 ? "1" : CommonString.getFormatInt(model.get("min_buy_count")) %>" maxlength="50"  dataType="Integer" msg="请输入最小起订量" />
    </div>
    <div class="formLeft"><span style="color:#F00">* </span>每单限购数量</div>
    <div class="formRight" style="width:190px;">
      <input type="text" class="jr_text" name="zd_max_buy_count" id="zd_max_buy_count" style="width:80px;" value="<%=CommonString.getFormatInt(model.get("max_buy_count")) %>" maxlength="50" />默认为0不限制
    </div>
    <!-- 
    <div class="formLeft">已售数量</div>
    <div class="formRight" style="width:190px; text-align:left;">
      <input type="text" style="width:80px;" class="jr_text" name="zd_sell_amount" id="zd_sell_amount" value="<%=CommonString.getFormatInt(model.get("sell_amount")) %>" maxlength="100" />
    </div>
     -->
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft">抢购开始时间</div>--%>
      <%--<div class="formRight" style="width: 150px;">--%>
      <%--<%--%>
      <%--String buy_begin_date = CommonDate.getFormatDate("yyyy-MM-dd HH:mm",model.get("buy_begin_date"));--%>
      <%--%>--%>
      <%--<input type="text" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" name="zd_pub_date" id="zd_pub_date" value="<%=buy_begin_date %>" />--%>
      <%--</div>--%>
      <%--<div class="formLeft">抢购结束时间</div>--%>
      <%--<div class="formRight" style="width: 150px;">--%>
      <%--<%--%>
      <%--String buy_end_date = CommonDate.getFormatDate("yyyy-MM-dd HH:mm",model.get("buy_end_date"));--%>
      <%--%>--%>
      <%--<input type="text" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" name="zd_pub_date" id="zd_pub_date" value="<%=buy_end_date %>" />--%>
      <%--</div>--%>
    <div style="clear:left;"></div>
    <div class="formLeft">商品简要说明</div>
    <div class="formRight">
      <input type="text" class="jr_text" name="zd_cus_cycle_tip" id="zd_cus_cycle_tip" value="<%=CommonString.getFormatPara(model.get("cus_cycle_tip")) %>" maxlength="100" />
    </div>
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft">周末旅行列表图片</div>--%>
      <%--<div class="formRight" style="width:400px;">--%>
      <%--<input type="text" readonly="readonly" style="width: 400px;float:left;" class="jr_text" name="zd_week_end_travle_img" id="zd_week_end_travle_img" value="<%=CommonString.getFormatPara(model.get("week_end_travle_img")) %>" />--%>
      <%--</div>--%>
      <%--<div class="formRight" style="width: 230px;"> <a href="<%=CommonString.getFormatPara(model.get("week_end_travle_img")) %>" id="a_week_end_travle_img" onclick='return hs.expand(this)'><img src="/backend/images/yulan.gif" /></a> <span id="week_end_travle_img"></span> 【<b style="color:red;">尺寸：540*240像素</b>】</div>--%>
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft">推荐月份</div>--%>
      <%--<div class="formRight" style="height:40px;width:650px;"> --%>
      <%--<input type="button" style="height:20px;margin-bottom:5px;"  name="allMonthSelect" id="allMonthSelect" value="全选" />&nbsp;&nbsp;--%>
      <%--<input type="button" style="height:20px;margin-bottom:5px;"  name="allMonthSelectDis" id="allMonthSelectDis" value="取消" /><br />--%>
      <%--<%=CommonForm.createCheckbox(enumMap202,CommonString.getFormatPara(model.get("recommend_month")),"recommend_month") %> --%>
      <%--<input type="hidden" name="zd_recommend_month" id="zd_recommend_month" value="" />--%>
      <%----%>
      <%--</div>--%>

      <%--<div style="clear:left;"></div>--%>
      <%--<div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">合伙人</span> </div>--%>
      <%--<div class="formLeft" style="width:150px; "><span style="color:#F00">* </span><span style="color:red;"><b>皇冠合伙人（<%=df.format(crown_partner_point*100) %>%）</b></span></div>--%>
      <%--<div class="formRight" style="width:190px; text-align:left;">--%>
      <%--<input type="text" class="jr_text" name="zd_crown_partner_payment" id="zd_crown_partner_payment" style="width:80px;" dataType="Require" msg="请输入皇冠合伙人提成" value="<%=CommonString.getFormatPara(model.get("crown_partner_payment")) %>" maxlength="100"/> 元--%>
      <%--</div>--%>
      <%--<div class="formLeft" style="width:150px; "><span style="color:#F00">* </span><span style="color:red;"><b>钻石合伙人（<%=df.format(diamond_partner_point*100) %>%） </b></span></div>--%>
      <%--<div class="formRight" style="width:190px; text-align:left;">--%>
      <%--<input type="text" class="jr_text" name="zd_diamond_partner_payment" id="zd_diamond_partner_payment" style="width:80px;" dataType="Require" msg="请输入钻石合伙人提成" value="<%=CommonString.getFormatPara(model.get("diamond_partner_payment")) %>" maxlength="100"/> 元--%>
      <%--</div>--%>
      <%--<div style="clear:left;"></div>--%>
      <%--<div class="formLeft" style="width:150px; "><span style="color:#F00">* </span><span style="color:red;"><b>黄金合伙人（<%=df.format(gold_partner_point*100) %>%） </b></span></div>--%>
      <%--<div class="formRight" style="width:190px; text-align:left;">--%>
      <%--<input type="text" class="jr_text" name="zd_gold_partner_payment" id="zd_gold_partner_payment" style="width:80px;" dataType="Require" msg="请输入黄金合伙人提成" value="<%=CommonString.getFormatPara(model.get("gold_partner_payment")) %>" maxlength="100"/> 元--%>
      <%--</div>--%>
      <%--<div class="formLeft" style="width:150px; "><span style="color:#F00">* </span><span style="color:red;"><b>二级会员（<%=df.format(junior_member_point*100) %>%） </b></span></div>--%>
      <%--<div class="formRight" style="width:190px; text-align:left;">--%>
      <%--<input type="text" class="jr_text" name="zd_junior_member_payment" id="zd_junior_member_payment" style="width:80px;" dataType="Require" msg="请输入二级会员提成" value="<%=CommonString.getFormatPara(model.get("junior_member_payment")) %>" maxlength="100"/> 元--%>
      <%--</div>--%>
      <%--<div style="clear:left;"></div>--%>
    <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">SEO</span> </div>
    <div class="formLeft"><span style="color:#F00">* </span>Title</div>
    <div class="formRight">
      <input type="text" class="jr_text" name="zd_seo_title" id="zd_seo_title" value="<%=CommonString.getFormatPara(model.get("seo_title")) %>" maxlength="100"/>
    </div>
    <div style="clear:left;"></div>
    <div class="formLeft"><span style="color:#F00">* </span>Keywords</div>
    <div class="formRight">
      <input type="text" class="jr_text" name="zd_seo_keywords" id="zd_seo_keywords" value="<%=CommonString.getFormatPara(model.get("seo_keywords")) %>" maxlength="100"/>
    </div>
    <div style="clear:left;"></div>
    <div class="formLeft"><span style="color:#F00">* </span>Description</div>
    <div class="formRight" style="height:80px;;">
    	<textarea class="jr_textarea" id="zd_seo_description" name="zd_seo_description" style="height:80px;width:500px"><%=CommonString.getFormatPara(model.get("seo_description")) %></textarea>
    </div>
    <div style="clear:left;"></div>
    <div id="paramId">
      <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">商品参数</span> </div>
      <%
		if(list != null && list.size() > 0){
		int i = 0;
		Map enumMap = null;
	%>
      <%
			for(Map m : list){
				i++;
				//显示非规格参数
				if(!CommonString.getFormatPara(m.get("is_key")).equals("1")){	
	%>
      <%
		if(CommonString.getFormatPara(m.get("type")).equals("2")){//枚举类型
			enumMap = CommonApplication.getEnumChildren(CommonString.getFormatPara(m.get("enum_no")),application);
	%>
      <div class="formLeft"><%=m.get("name")%></div>
      <div class="formRight" style="width:190px">
        <select class="jr_select" name="param" id="<%=CommonString.getFormatPara(m.get("no"))%>" lang="'product_no':'<%=no%>' ,'no':'<%=CommonString.getFormatPara(m.get("no"))%>' , 'name':'<%=CommonString.getFormatPara(m.get("name"))%>' , 'type':'2', 'order_no':'<%=CommonString.getFormatPara(m.get("order_no"))%>' , 'enum_no':'<%=CommonString.getFormatPara(m.get("enum_no"))%>'" >
          <option value="">--请选择--</option>
          <%=CommonForm.createSelect(enumMap, CommonString.getFormatPara(m.get("value"))) %>
        </select>
      </div>
      <%
		}else{//文本类型
	%>
      <div class="formLeft"><%=m.get("name")%></div>
      <div class="formRight" style="width:190px">
        <input type="text" class="jr_text" name="param" id="<%=CommonString.getFormatPara(m.get("no"))%>" lang="'product_no':'<%=no%>' ,'no':'<%=CommonString.getFormatPara(m.get("no"))%>' , 'name':'<%=CommonString.getFormatPara(m.get("name"))%>' , 'type':'1', 'order_no':'<%=CommonString.getFormatPara(m.get("order_no"))%>' , 'enum_no':''" value="<%=CommonString.getFormatPara(m.get("value"))%>" maxlength="50"/>
      </div>
      <%}%>
      <%if(i%2==0){%>
      	<div style="clear:left;"></div>
      <%}%>
      <%
				}
			}
		}
	%>
	
	<!--规格参数-->
      <%
     	int paramCount = 0;//保存规格参数的数量
        if(!category.equals("") && list != null && list.size() > 0){
            Map enumMap = null;
    %>
      <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">规格参数</span> </div>
	<%
            int i = 0;
            for(Map m:list){
                i++;
	%>
    <%
    	//显示枚举类的规格参数
        if(CommonString.getFormatPara(m.get("is_key")).equals("1") && CommonString.getFormatPara(m.get("type")).equals("2")){
        	List enumProductList = (List)application.getAttribute("enumProductList");
        	enumMap = CommonApplication.getEnumChildren(CommonString.getFormatPara(m.get("enum_no")),enumProductList);
            if(enumMap != null){
            	paramCount++;
    %>
    
    <div class="formLeft"><span style="color:#F00">* </span><%=m.get("name")%></div>
    <div class="formRight" style="height:100%;line-height:30px;" id="keyparamDiv" lang="'no':'<%=CommonString.getFormatPara(m.get("enum_no"))%>','name':'<%=CommonString.getFormatPara(m.get("name"))%>'">
    	<input type="hidden" id="keyparamTitle_<%=i %>" value="<%=m.get("name")%>" />
    	<%
                for(Object key : enumMap.keySet()){
        %>
        	<div style="width:120px;text-align:left;float:left;">
        	<input type="checkbox" id="<%=key%>" onclick="createStoreTable()" name="<%="keyparam_"+CommonString.getFormatPara(m.get("enum_no"))%>" value="{'no':'<%=CommonString.getFormatPara(key)%>','name':'<%=CommonString.getFormatPara(enumMap.get(key))%>'}" />
            &nbsp;&nbsp;<label for="<%=key%>"><%=CommonString.getFormatPara(enumMap.get(key))%></label>
            </div>
        <%
                }
        %>
    </div>
    <div style="clear:left;"></div>
      <%
            }
        }
    %>
      <%
            }
        }
    %>
      
      <!--价格&库存-->
      <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">价格&库存</span> </div>
      <style type="text/css">
    .tableStyle01 { width:760px; border-collapse:collapse; border:#ccc 1px solid; margin:0px auto; clear:both;}
    .tableStyle01 td,.tableStyle01 th { border:#ccc 1px solid; text-align:left; padding:3px 5px; line-height:18px;}
    .tableStyle01 th { font-weight:bold; background-color:#dddddd; color:#000;}
    </style>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style="display:none" class="tableStyle01" id="paramTable" lang="'no':'','name':''">
        <tr>
          <th width="10%" style="text-align:center"></th>
            <th width="10%" style="text-align:center">市场价</th>
            <th width="10%" style="text-align:center">销售价</th>
            <th width="10%" style="text-align:center">库存</th>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="text" class="jr_text" name="param" id="" lang="'product_no':'' ,'no':'' , 'name':'' , 'type':'1', 'order_no':'' , 'enum_no':''" value="" maxlength="50"/></td>
          <td><input type="text" class="jr_text" name="param" id="" lang="'product_no':'' ,'no':'' , 'name':'' , 'type':'1', 'order_no':'' , 'enum_no':''" value="" maxlength="50"/></td>
          <td><input type="text" class="jr_text" name="param" id="" lang="'product_no':'' ,'no':'' , 'name':'' , 'type':'1', 'order_no':'' , 'enum_no':''" value="" maxlength="50"/></td>
        </tr>
      </table>
    </div>
    <div class="group" style="height:22px;">
        <div style="float:left; white-space:nowrap;"><span><img
                src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif"/></span> <span
                class="groupTitle">商品图片</span>建议：430*430
        </div>
      <span id="sub_img" style="float:right"></span> </div>
    <div class="w100 l">
      <div id="flashContainer" class="w100 l" style="height:auto; text-align:center;margin-left:16px; *margin-left:16px"></div>
      <%
        if(imgCount > 0){
      %>
      <div class="w100 l" style="margin-left:30px"> <span style=" display:block; width: 480px; padding-left:10px;"> <span id="setMainImg" style="cursor:pointer; color:#000000; font-family: 微软雅黑"><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/database.gif" align="absmiddle" style="margin-bottom:2px" /> 设为主图</span> <span id="del_img" style="cursor:pointer; color:#000000; font-family: 微软雅黑"><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/delete.gif" align="absmiddle" style="margin-bottom:2px" /> 删除</span> <span style="color:#999999">（友情提示：单击图片选中，拖动图片进行排序。）</span> </span> </div>
      <%}%>
      <div style="clear:both;"></div>
    </div>
    <%
		if(imgCount > 0){
	%>
    <div style="border: 1px solid #ccc; width: 700px; height: auto; overflow-y: auto; margin-left:30px; position:relative;" id="sortable">
      <%
		if(null!=images&&images.size()>0){
			Map subModel = null;
			for(int i=0;i<images.size();i++){
				subModel = images.get(i);
	%>
      <div class="single_img" id="<%=subModel.get("uuid") %>" title="<%=subModel.get("img") %>">
        <div><img class="show_img" width="130px;" src="<%=resDomain+subModel.get("small_img") %>" /></div>
        <div class="toobar">
          <%
    		if(mainImageName.equals(subModel.get("img"))){
    %>
          <input myid="<%=subModel.get("uuid") %>" type="text" class="miaoshu" oldval="<%=subModel.get("title") %>" style="border:none; border-right: 1px solid #ccc; font-weight:bold; width: 100px; height: 18px; color:#FF0000; text-align:center" value="<%=subModel.get("title").equals("")?"主图":subModel.get("title") %>" />
          <%
				}else{ 
			%>
          <input myid="<%=subModel.get("uuid") %>" type="text" class="miaoshu" oldval="<%=subModel.get("title") %>" style="border:none; border-right: 1px solid #ccc; width: 100px; height: 18px;text-align:center" value="<%=subModel.get("title") %>" />
          <%
				}
			%>
          <a href="<%=resDomain+subModel.get("img") %>" onclick="return hs.expand(this)" class="highslide"> <img style="position: absolute; bottom: 0px; right:3px; width: 18px; height: 18px;" src="/images/fangda.gif" /> </a> </div>
        <div class="shade"></div>
      </div>
      <%
                    }
                }
            %>
      <div style="clear: left;"></div>
    </div>
    <%
        }
    %>
    <style>
    .formRight,#editor_content2 {position:relative;} 
    </style>
    <div style="float:left; border: 1px solid #ccc; width: 700px; position:relative; height: auto; overflow-y: auto; margin-left:30px;display:none" id="sortable2"> </div>
      <div class="group"><span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif"/></span> <span
              class="groupTitle">商品详情</span>图片建议：1240*699
      </div>
      <div class="formRight" style="width:700px; height:500px; padding-left:30px">
      <script type="text/plain" id="editor_content3" style="width:700px; height:400px;"><%=CommonString.getFormatPara(model.get("intro")) %></script>
      <input type="hidden" name="zd_intro" id="zd_intro" value="" />
    </div>
    </div>
    <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">(手机端)商品详情</span> </div>
    <div class="formRight" style="width:700px; height:460px; padding-left:30px"> 
      <script type="text/plain" id="editor_content5" style="width:700px; height:400px;"><%=CommonString.getFormatPara(model.get("m_intro")) %></script>
      <input type="hidden" name="zd_m_intro" id="zd_m_intro" value="" />
    </div>
    <div class="group"> <span><img src="/plugin/ui/ligerUI/ligerUI/skins/icons/communication.gif" /></span> <span class="groupTitle">扩展信息</span> </div>
    <div class="formLeft">是否上架</div>
    <div class="formRight" style="width:190px"> <%=CommonForm.createIsRadio(CommonString.getFormatPara(model.get("is_buy")),"zd_is_buy") %> </div>
     <div style="clear:left;"></div>
    <div class="formLeft">是否显示</div>
    <div class="formRight" style="width:190px"> <%=CommonForm.createIsRadio(CommonString.getFormatPara(model.get("is_show")),"zd_is_show") %> </div>
    <div class="formLeft">上架时间</div>
    <div class="formRight" style="width: 150px;">
      <%
			String nowDate = CommonDate.getFormatDate("yyyy-MM-dd HH:mm",model.get("pub_date"));
			if("".equals(nowDate)){
				nowDate = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			}
		%>
      <input type="text" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" name="zd_pub_date" id="zd_pub_date" value="<%=nowDate %>" />
    </div>
    <div style="clear:left;"></div>
    <div class="formLeft">是否推荐</div>
    <div class="formRight" style="width:190px"> <%=CommonForm.createIsRadio(CommonString.getFormatPara(model.get("is_rec")).equals("")?"0":CommonString.getFormatPara(model.get("is_rec")),"zd_is_rec") %> </div>
    <div class="formLeft">点击次数</div>
    <div class="formRight" style="text-align: left;width:150px">
      <input type="text" class="jr_text" style="width: 150px;" name="zd_view_count" id="zd_view_count" value="<%=CommonString.getFormatPara(model.get("view_count")) %>" />
    </div>
  </div>
  <input type="hidden" name="tableName" id="tableName" value="<%=tableName %>" />
  <input type="hidden" name="zd_id" id="zd_id" value="<%=CommonString.getFormatPara(model.get("id")) %>" />
  <input type="hidden" name="zd_order_no" id="zd_order_no" value="<%=CommonString.getFormatPara(model.get("order_no")) %>" />
  <input type="hidden" name="zd_param" id="zd_param" value="<%=CommonString.getFormatPara(model.get("param")) %>" />
  <input type="hidden" name="zd_param_key" id="zd_param_key" value="<%=CommonString.getFormatPara(model.get("param_key")) %>" />
  <input type="hidden" name="zd_param_key_no" id="zd_param_key_no" value="<%=CommonString.getFormatPara(model.get("param_key_no")) %>" />
  <input type="hidden" name="zd_img" id="zd_img" dataType="Require" msg="请上传图片" value="<%=CommonString.getFormatPara(model.get("img")) %>" />
  <input type="hidden" name="zd_category" id="zd_category" value="<%=CommonString.getFormatPara(model.get("category")) %>" />
  <input type="hidden" name="zd_channel_uuid" id="zd_channel_uuid" value="<%=channelUUID %>" />
  <input type="hidden" name="eventAfter" id="eventAfter" value="" />
</form>
</body>
</html>
<script type="text/javascript" src="/plugin/jquery/jquery.form.js"></script>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js?tab" type="text/javascript"></script>
<script src="/plugin/validator/wofoshan/validator.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/plugin/other/highslide/highslide.min.js"></script>
<script type="text/javascript" src="<%=resDomain%>/plugin/upload/jr_upload.js"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/plugin/ui/jqueryUI/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="http://img.52sdskj.com/plugin/upload/jr_upload.js"></script>
<script type="text/javascript">
	hs.graphicsDir = '/plugin/other/highslide/graphics/';
	hs.wrapperClassName = 'wide-border';
	
	jQuery("#week_end_travle_img").JrUpload({
        remotUrl: "http://img.52sdskj.com/upload.jsp",
		folder : "saygou" ,
		watermark:false,
		callback : "setWeekendImg"
	});
	function setWeekendImg(data){
        var imgUrl = "http://img.52sdskj.com" + data;
		jQuery("#a_week_end_travle_img").attr("href",imgUrl);
		jQuery("#zd_week_end_travle_img").val(imgUrl);
	}
		
	function doSub(dialog){
//		var idStr = "";
//		$("input[name='recommend_month']:checkbox").each(function () {
//			if ($(this).attr("checked")) {
//				idStr += $(this).val()+",";
//			}
//		})
//		if(idStr.length>1){
//			idStr = idStr.substr(0,idStr.length-1);
//		}
//		$("#zd_recommend_month").val(idStr);

        //会员价格判断
        var price_101 = $("#zd_price_101").val();
        var price_102 = $("#zd_price_102").val();
        var price_103 = $("#zd_price_103").val();
        if (price_101 <= 0) {
            alert("请填写钻石会员价格");
            return false;
        }
        if (price_102 <= 0) {
            alert("请填写黄金会员价格");
            return false;
        }
        if (price_103 <= 0) {
            alert("请填写白银会员价格");
            return false;
        }
		
		var rs = Validator.Validate(document.getElementById("theform"),1);
		if(rs){
            if (confirm("确定已经正确填写会员价格？")) {
				savaProductAndParam(dialog);
			}
		}
	}

    <%----%>
    <%--chooseGuest();--%>
    <%--function chooseGuest(){--%>
    <%--var idStr = "<%=CommonString.getFormatPara(model.get("recommend_month")) %>";--%>
    <%--if(idStr!=""){--%>
    <%--var idArr = idStr.split(",");--%>
    <%--for(var i=0;i<idArr.length;i++){--%>
    <%--if(idArr[i]){--%>
    <%--$("input[name='recommend_month']:checkbox").each(function () { --%>
    <%--var v = $(this).val();--%>
    <%--if(v == idArr[i]) { --%>
    <%--$(this).attr("checked","checked"); --%>
    <%--} --%>
    <%--}) --%>
    <%--}--%>
    <%--}--%>
    <%--}--%>
    <%----%>
    <%--}--%>
    <%----%>
	//全选
    //	$("#allMonthSelect").click(function() {
    //		$("input[name='recommend_month']:checkbox").each(function () {
    //			$(this).attr("checked", true);
    //		});
    //
    //	});
    //	//取消
    //	$("#allMonthSelectDis").click(function() {
    //		$("input[name='recommend_month']:checkbox").each(function () {
    //			$(this).attr("checked", false);
    //		});
    //
    //	});
	
	//规格参数信息
	var paramKeyMapJson = '<%=paramKeyMapJson.toString() %>';
	var paramKeyMapData = eval('(' + paramKeyMapJson + ')');
	var paramKeyMarketPirceMapJson = '<%=paramKeyMarketPirceMapJson.toString() %>';
	var paramKeyMarketPirceMapData = eval('(' + paramKeyMarketPirceMapJson + ')');
	var paramKeySalePirceMapJson = '<%=paramKeySalePirceMapJson.toString() %>';
	var paramKeySalePirceMapData = eval('(' + paramKeySalePirceMapJson + ')');
	var paramKeyStoreMapJson = '<%=paramKeyStoreMapJson.toString() %>';
	var paramKeyStoreMapData = eval('(' + paramKeyStoreMapJson + ')');
	
	
	//创建库存表格
	function createStoreTable(){
		var paramCount = <%=paramCount %>;
		var paramNoTitleArr = new Array();
		var paramCountArr = new Array();
		var paramSelectJson = "";
		
		var z = 0;
		if(paramCount > 0){
			paramSelectJson = "{";
			for(var i=1;i<=paramCount;i++){
				var tempCount = $("input[name='keyparam_000"+i+"']:checked").length;
				
				if(tempCount>0){
					paramNoTitleArr[z] = i;
					paramCountArr[z] = tempCount;
					paramSelectJson += "param_"+z+":[";
					$("input[name='keyparam_000"+i+"']:checked").each(function(){
				          var jsonobj=eval('('+this.value+')')
				          paramSelectJson += this.value+",";
				    });
				    paramSelectJson = paramSelectJson.substring(0,paramSelectJson.length-1);
				    paramSelectJson += "],";
				    z++;
				}
			}
			if(paramSelectJson!="{"){
				paramSelectJson = paramSelectJson.substring(0,paramSelectJson.length-1);
			}
			
			paramSelectJson += "}";
		}

		//循环生成标题table
		var paramTitleHtml = "<tr>";
		for(var n = 0;n<paramNoTitleArr.length;n++){
			var paramTitle = jQuery("#keyparamTitle_"+paramNoTitleArr[n]).val();
			paramTitleHtml += "<th width=\"10%\" style=\"text-align:center\">"+paramTitle+"</th>";
		}
        paramTitleHtml += "  <th width=\"10%\" style=\"text-align:center\" id=\"param_price_t\">市场价</th>";
        paramTitleHtml += "  <th width=\"10%\" style=\"text-align:center\">销售价</th>";
        paramTitleHtml += "  <th width=\"10%\" style=\"text-align:center\">库存</th></tr>";
        

		//循环生成内容table
		var paramContentHtml = "";
		//计算总行数
		var totalCount = 1;
		for(var j = 0;j<paramCountArr.length;j++){
			totalCount = totalCount*paramCountArr[j];
		}
		var jsonobj=paramSelectJson==""?"":eval('('+paramSelectJson+')');
		var firstLevelNo = "";
		var secondLevelNo = "";
		var threeLevelNo = "";
		var fourLevelNo = "";
		if(typeof(jsonobj) == undefined){
			for(var r = 0;r<totalCount;r++){
				var paramNO = "";
				paramContentHtml += "<tr>";
				//计算第一层层数
				var totalOneCount = 1;
				for(var nn =1 ;nn<paramCountArr.length;nn++){
					totalOneCount = totalOneCount*paramCountArr[nn];
				}
				if(r%totalOneCount==0){
					var thisLevelCount = paramCountArr[0];
					//var nextLevelCount = paramCountArr.length>1?paramCountArr[1]:1;
					//var key = (parseInt((r+1)/nextLevelCount)%thisLevelCount);
					var key = parseInt((r+1)/totalOneCount)%thisLevelCount;
					var tempName = jsonobj.param_0[key].name;
					firstLevelNo = jsonobj.param_0[key].no;
					paramContentHtml += "<td rowspan=\""+totalOneCount+"\">"+tempName+"</td>";
				}
				if(paramCountArr.length>1){
					//计算第二层层数
					var totalTwoCount = 1;
					for(var nn =2 ;nn<paramCountArr.length;nn++){
						totalTwoCount = totalTwoCount*paramCountArr[nn];
					}
					if(r%totalTwoCount==0){
						var thisLevelCount = paramCountArr[1];
						//var nextLevelCount = paramCountArr.length>2?paramCountArr[2]:1;
						//var key = (parseInt((r+1)/nextLevelCount)%thisLevelCount);
						var key = parseInt((r+1)/totalTwoCount)%thisLevelCount;
						var tempName = jsonobj.param_1[key].name;
						secondLevelNo = "-"+jsonobj.param_1[key].no;
						paramContentHtml += "<td rowspan=\""+totalTwoCount+"\">"+tempName+"</td>";
					}
				}
				if(paramCountArr.length>2){
					//计算第三层层数
					var totalThreeCount = 1;
					for(var nn =3 ;nn<paramCountArr.length;nn++){
						totalThreeCount = totalThreeCount*paramCountArr[nn];
					}
					if(r%totalThreeCount==0){
						var thisLevelCount = paramCountArr[2];
						//var nextLevelCount = paramCountArr.length>3?paramCountArr[3]:1;
						//var key = (parseInt((r+1)/nextLevelCount)%thisLevelCount);
						var key = parseInt((r+1)/totalThreeCount)%thisLevelCount;
						var tempName = jsonobj.param_2[key].name;
						threeLevelNo = "-"+jsonobj.param_2[key].no;
						paramContentHtml += "<td rowspan=\""+totalThreeCount+"\">"+tempName+"</td>";
					}
				}
				if(paramCountArr.length>3){
					//计算第四层层数
					var totalFourCount = 1;
					for(var nn =4 ;nn<paramCountArr.length;nn++){
						totalFourCount = totalFourCount*paramCountArr[nn];
					}
					if(r%totalFourCount==0){
						var thisLevelCount = paramCountArr[3];
						//var nextLevelCount = paramCountArr.length>4?paramCountArr[4]:1;
						//var key = (parseInt((r+1)/nextLevelCount)%thisLevelCount);
						var key = parseInt((r+1)/totalFourCount)%thisLevelCount;
						var tempName = jsonobj.param_3[key].name;
						fourLevelNo = "-"+jsonobj.param_3[key].no;
						paramContentHtml += "<td rowspan=\""+totalFourCount+"\">"+tempName+"</td>";
					}
				}
				paramNO = firstLevelNo;
				if(secondLevelNo!=""){
					paramNO += secondLevelNo;
				}
				if(threeLevelNo!=""){
					paramNO += threeLevelNo;
				}
				if(fourLevelNo!=""){
					paramNO += fourLevelNo;
				}
				paramContentHtml += "<td><input type=\"text\" class=\"jr_text\" name=\"param_market_price\" id=\"param_market_price_"+paramNO+"\" lang=\""+paramNO+"\" value=\"\" maxlength=\"50\"/></td>";
		        paramContentHtml += "<td><input type=\"text\" class=\"jr_text\" name=\"param_sale_price\" id=\"param_sale_price_"+paramNO+"\" lang=\""+paramNO+"\" value=\"\" maxlength=\"50\"/></td>";
		       	paramContentHtml += "<td><input type=\"text\" class=\"jr_text\" name=\"param_store\" id=\"param_store_"+paramNO+"\" lang=\""+paramNO+"\" value=\"\" maxlength=\"50\"/></td>";
				paramContentHtml += "</tr>";
				
			}
			jQuery("#paramTable").html(paramTitleHtml+paramContentHtml);
			jQuery("#paramTable").css("display","");
			
			//为表格赋值
			setStoreTalbe();
		
		}
	}
	
	//为表格赋值
	function setStoreTalbe(){
		var paramKV = document.getElementsByName("param_market_price");
		for(var i =0;paramKV.length > 0 && i<paramKV.length;i++){
			var temp_no = paramKV[i].lang;
			if(jQuery("#param_market_price_"+temp_no).val()==""){
				jQuery("#param_market_price_"+temp_no).val(paramKeyMarketPirceMapData[temp_no]);
			}
			if(jQuery("#param_sale_price_"+temp_no).val()==""){
				jQuery("#param_sale_price_"+temp_no).val(paramKeySalePirceMapData[temp_no]);
			}
			if(jQuery("#param_store_"+temp_no).val()==""){
				jQuery("#param_store_"+temp_no).val(paramKeyStoreMapData[temp_no]);
			}
		}
	}
	
	//保存方法
	function savaProductAndParam(dialog){
		//参数保存----
		var paramV = document.getElementsByName("param");
		var zd_param = "["
		for(var i =0;paramV.length > 0 && i<paramV.length;i++){
			//组装json
			if(i==paramV.length-1){
				zd_param += "{"+paramV[i].lang+",'value':'"+paramV[i].value+"'}";	
			}else{
				zd_param += "{"+paramV[i].lang+",'value':'"+paramV[i].value+"'},";
			}
		}
		zd_param += "]";
		jQuery("#zd_param").val(zd_param);
		
		//规格参数内容保存----
		var paramKV = document.getElementsByName("param_market_price");
		var zd_param_key = "["
		for(var i =0;paramKV.length > 0 && i<paramKV.length;i++){
			var temp_no = paramKV[i].lang;
			var temp_market_price = jQuery("#param_market_price_"+temp_no).val();
			var temp_sale_price = jQuery("#param_sale_price_"+temp_no).val();
			var temp_store = jQuery("#param_store_"+temp_no).val();
			//组装json
			if(i==paramKV.length-1){
				zd_param_key += "{'no':"+temp_no+",'market_price':'"+temp_market_price+"','sale_price':'"+temp_sale_price+"','store':'"+temp_store+"'}";	
			}else{
				zd_param_key += "{'no':"+temp_no+",'market_price':'"+temp_market_price+"','sale_price':'"+temp_sale_price+"','store':'"+temp_store+"'},";
			}
		}
		zd_param_key += "]";
		
		//保存参数
		jQuery.ajax({
			url : '/backend/action/ajax_cud.jsp',	
			data : { paramStr:zd_param , product_no:'<%=no%>' , flag:'saveParamValue' , enumNo:'106013' },
			type : 'post',
			async : false
		});
		//保存规格内容
		jQuery.ajax({
			url : '/backend/action/ajax_cud.jsp',	
			data : { paramKeyStr:zd_param_key , product_no:'<%=no%>' , flag:'saveParamKeyValue' , enumNo:'106013' },
			type : 'post',
			async : false
		});

		//参数保存----
		
		//关键参数项保存，设置该产品有的关键参数项
		var keyparam = "[";
		var keyPramNo = "";
		jQuery.each(jQuery("div[id^=keyparamDiv]"),function(){
			keyparam += "{"+jQuery(this).attr("lang")+",'param':[";
			var pKey = jQuery(this).find("input:checkbox");
			for(var i = 0; i < pKey.length; i++){
				if(pKey[i].checked){
					keyparam += pKey[i].value+",";	
					keyPramNo += pKey[i].id+"-";	
				}
			}
			if(keyparam.substring(keyparam.length-1) == ","){
				keyparam = keyparam.substring(0,keyparam.length-1);
			}
			keyparam += "]},";
		});
		if(keyparam.substring(keyparam.length-1) == ","){
			keyparam = keyparam.substring(0,keyparam.length-1);
			keyPramNo = keyPramNo.substring(0,keyPramNo.length-1);
		}
		keyparam += "]";
		console.log(keyparam);
		jQuery("#zd_param_key").val(keyparam);
		jQuery("#zd_param_key_no").val(keyPramNo);
		
		jQuery("#theform").ajaxSubmit({
				type : "POST",
				async : false ,
				success : function(data) {
					var rs = parseInt(jQuery.trim(data), 10);
					if (rs > 0) {
						<%
							if(id.equals("")){ //添加产品时，生成商品短编号
						%>
						$.ajax({
							type:"post",
							url:"/backend/action/ajax_r.jsp",
							data:{flag:"updateProductShortNo", no:$("#zd_no").val(), enumNo:"106013"}
						});
						<%
							}
						%>		
						
						//$.ajax({
						//	type:"post",
						//	url:"/backend/action/ajax_r.jsp",
						//	data:{flag:"generateProductIndex",no:$("#zd_no").val(),enumNo:"106013"}
						//});				
						
						window.parent.jQuery.ligerDialog.success("操作成功", "提示", function(){
							dialog.close();
						});
					} 
				}
			});	
	}
	
	//为参数赋值
	var param = <%=CommonString.getFormatPara(model.get("param")).equals("")?"[]":CommonString.getFormatPara(model.get("param"))%>;
	for(var i = 0; i < param.length; i++){
		if(jQuery("#"+param[i].no) != null){
			jQuery("#"+param[i].no).val(param[i].value);
		}
	}
	
	//为关键参数项赋值
	var paramKey = <%=CommonString.getFormatPara(model.get("param_key")).equals("")?"[]":CommonString.getFormatPara(model.get("param_key"))%>;
	for(var i = 0; i < paramKey.length; i++){
		for(var j = 0; j < paramKey[i].param.length; j++){
			var paramA = paramKey[i].param[j];
			jQuery("#"+paramA.no).attr("checked","checked");
		}
	}
	
	//生成表格
	createStoreTable();
	//为表格赋值
	setStoreTalbe();
	
	function showParam(category){
		jQuery.ajax({
			url : 'get_param_html.jsp',
			data : { category : category , no : '<%=no%>' } ,
			type : 'post' ,
			async : false ,
			success : function(data){
				jQuery("#paramId").css("display","block");
				jQuery("#paramId").html(data);
			}
		});
	}
	//
	var ue_content3 = new baidu.editor.ui.Editor({
    	textarea : 'zd_intro',
    	autoHeightEnabled:false,
    	watermark : false,
    	minFrameHeight:400
    });
    ue_content3.render('editor_content3');
    ue_content3.addListener("selectionchange",function(){
	    var state_content = ue_content3.queryCommandState("source");
	    document.getElementById("zd_intro").value=ue_content3.getContent();
	});
	document.getElementById("zd_intro").value=ue_content3.getContent();
	
	//phone
	var ue_content5 = new baidu.editor.ui.Editor({
    	textarea : 'zd_m_intro',
    	autoHeightEnabled:false,
    	watermark : false,
    	minFrameHeight:300
    });
    ue_content5.render('editor_content5');
    ue_content5.addListener("selectionchange",function(){
	    var state_content = ue_content5.queryCommandState("source");
	    document.getElementById("zd_m_intro").value=ue_content5.getContent();
	});
	document.getElementById("zd_m_intro").value=ue_content5.getContent();
		
	//图片批量上传----------
	jQuery("#sub_img").JrUpload({
		remotUrl : "<%=resDomain%>/upload.jsp",
		folder : "saygou" ,
		watermark:false,
		multi:true,
		callback : "setSubImg"
	});
	function setSubImg(data){
		if(data != ""){
			<%if(model.get("id") == null){//新增数据时上传图片%>
				var dataArr = data.split(",");
				//页面赋值
				var imgHtml = "";
				for(var i = 0;i < dataArr.length;i++){
				  imgHtml += "<div class=\"single_img\" id=\"\">";
				  imgHtml += "<div><img class=\"show_img\" width=\"130px\" height=\"100px\" src=\"<%=resDomain %>"+dataArr[i]+"\" /></div>";
				  imgHtml += "<div class=\"shade\"></div>";
				  imgHtml += "<div style=\"display:inline;\"><a href=\"javascript://void(0);\" onclick=\"setMainImgByAdding(this);\">设为主图</a><a href=\"javascript://void(0);\" onclick=\"deleteImgByAdd(this);\" style=\"margin-left:5px;\">删除</a></div>";
				  imgHtml += "</div>";
				}
				imgHtml += "<div style=\"clear: left;\"></div>";
				jQuery("#sortable2").html(imgHtml);
				jQuery("#sortable2").css("display","block");
			<%}%>
			saveImgToDb(data);//保存到数据库
		}
	}
	/*将图片保存到数据库*/
	function saveImgToDb(str){
		var data = {
			flag : 'saveSubImg',
			enumNo : '106013',
			imgCount: '<%=imgCount%>',
			parent_id : '<%=no %>',
			channel_uuid : '<%=channelUUID %>',
			imgStr : str
		};
		
		var firstImg = str.indexOf(",")>0?str.substring(0,str.indexOf(",")):str;
		if("<%=imgCount%>"=="0" || jQuery("#zd_img").val()==""){//若原来没有图片，设置上传的第一张为主图
			jQuery("#zd_img").val(firstImg);
		}
		jQuery.ajax({
				url:"/backend/action/ajax_cud.jsp",
				data:data,
				success:function(data){
					if(jQuery.trim(data)=='ok'){
						<%if(model.get("id") != null){//若修改数据时上传图片%>
							if("<%=imgCount%>"=="0" || jQuery("#zd_img").val()==""){//若原来没有图片，设置上传的第一张为主图
								jQuery.ajax({
									url:'/backend/action/ajax_cud.jsp',
									data:{'flag':'setMainImg','imgSrc':firstImg,'tableName':'<%=tableName%>','parent_id':'<%=no%>','enumNo':'106013'},
									type:'post',
									async:false
								});	
							}
							window.location.reload();
						<%}%>
					}
				}
			});
		
	}
	
	function setMainImgByAdding(obj){
		var img = $(obj).parents("div.single_img").find("img.show_img").attr("src");
		img = img.replace("<%=resDomain %>","");
		$("#zd_img").val(img);
		$(obj).parents("div.single_img").parent("div").find("div.main_img").remove();
		$(obj).parents("div.single_img").append("<div class=\"main_img\" style=\"display:inline;\"> (主图)</div>");
	}
	
	jQuery("#sortable").sortable({
		stop : function(event, ui) {
			doSort();
		}
	});
	function doSort(){
		var sortHtml = "";
		var myid = "";
		jQuery.each(jQuery("#sortable>div"),function(index,data){
			myid =  jQuery(this).attr("id");
			if(myid==undefined){
				return;
			}
			sortHtml +=myid+",";
		});
		sortHtml = sortHtml.substring(0,sortHtml.length-1);
		jQuery.ajax({
			url:"/backend/action/ajax_cud.jsp",
			type:"post",
			data:{'flag':'saveSort',"tableName":"gift_sub_image","sortId":sortHtml,'enumNo':'106013'},
			async:false,
			cache:false
		});
	}
	jQuery("#sortable").disableSelection();
	jQuery(".single_img .show_img").click(function(){
		var obj = jQuery(this).parent().parent();
		obj.removeClass("ccc");
		obj.addClass("blue");
		obj.css("border","1px solid blue");
		obj.find(".shade").show();
	});
	jQuery(".shade").click(function(){
		var obj = jQuery(this).parent();
		obj.removeClass("blue");
		obj.addClass("ccc");
		obj.css("border","1px solid #ccc");
		obj.find(".shade").hide();
	});
	hs.graphicsDir = '/plugin/other/highslide/graphics/';
	hs.wrapperClassName = 'wide-border';
	var imageData = [],          //用于保存从服务器返回的图片信息数组
	selectedImageCount = 0;  //当前已选择的但未上传的图片数
	
	
	jQuery("#sortable2").sortable({
		stop : function(event, ui) {
			doSort2();
		}
	});
	function doSort2(){
		var imgs = "";
		jQuery.each(jQuery("#sortable2>div.single_img"),function(index,data){
			var img = $(this).find("img.show_img").attr("src");
			img = img.replace("<%=resDomain %>","");
			imgs += img + ",";
		});
		imgs = imgs.substring(0, imgs.length-1);
		
		jQuery.ajax({
			url:"/backend/action/ajax_cud.jsp",
			type:"post",
			data:{'flag':'saveSortByAdd',"tableName":"gift_sub_image","product_no":"<%=no %>","sortImg":imgs,'enumNo':'106013'},
			async:false,
			cache:false
		});
	}
	
	function deleteImgByAdd(obj){
		if(confirm("确定要删除吗？")){
			var img = $(obj).parents("div.single_img").find("img.show_img").attr("src");
			img = img.replace("<%=resDomain %>","");
			
			jQuery.ajax({
				url:"/backend/action/ajax_cud.jsp",
				type:"post",
				data:{'flag':'deleteImgByAdd',"tableName":"gift_sub_image","product_no":"<%=no %>","img":img,'enumNo':'106013'},
				async:false,
				cache:false,
				success:function(result){
					if($.trim(result) == "ok"){
						if($(obj).parents("div.single_img").children("div.main_img").length>0){
							$("#zd_img").val("");
						}
						$(obj).parents("div.single_img").remove();
					}
				}
			});
		}
	}
	
	/**	
	jQuery(".miaoshu").blur(function(){
		var oldval = jQuery(this).attr("oldval");
		var selfval = this.value;
		var id = jQuery(this).attr("myid");
		if(oldval!=selfval){
			jQuery.post("/action/ajax_cud.jsp",{
				'flag':'commonUpdate',
				'tableName':'gift_sub_image',
				'id':id,
				'key':'title',
				'value':selfval
			});
		}
	});
	*/
	jQuery("#del_img").click(function(){
		var blue = jQuery(".blue");
		if(blue.length<=0){
			alert("请单击选择您要删除的图片");
			return;
		}
		if(blue.length == "<%=imgCount%>"){
			alert("至少要保留一张图片");	
			return false;
		}
			if(confirm("确定要删除选中的"+blue.length+"张图片吗？")){
				var ids = "";
				jQuery.each(blue,function(index,data){
					ids += "'"+this.getAttribute('id')+"',";
				});
				if(ids.indexOf(',')!=-1){
					ids=ids.substring(0,ids.length-1);
				}
				jQuery.ajax({
					url:'/backend/action/ajax_cud.jsp',
					data:{'flag':'groupDel','ids':ids,'tableName':'gift_sub_image','enumNo':'106013'},
					type:'post',
					async:false,
					success:function(data){
						if(jQuery.trim(data)=='ok'){
							window.location.reload();
						}
					}
				});	
			}
		});
	//});
	
	jQuery("#setMainImg").click(function(){
		var blue = jQuery(".blue");
		if(blue.length<=0){
			alert("请单击选择您要设置为主图的图片");
			return;
		}
			if(confirm("确定要把选中的图片设置为主图吗？")){
				var imgSrc = "";
				jQuery.each(blue,function(index,data){
					imgSrc = this.getAttribute('title');
					return false;
				});
				if(imgSrc.indexOf(',')!=-1){
					imgSrc=ids.substring(0,ids.length-1);
				}
				jQuery.ajax({
					url:'/backend/action/ajax_cud.jsp',
					data:{'flag':'setMainImg','imgSrc':imgSrc,'tableName':'<%=tableName%>','parent_id':'<%=no%>','enumNo':'106013'},
					type:'post',
					async:false,
					success:function(data){
						if(jQuery.trim(data)=='ok'){
							window.location.reload();
						}
					}
				});	
			}
		//});
	});
	//图片批量上传----------

    <%--function countPartnerPayment(){--%>
    <%--var price = $("#zd_price_promotion").val();--%>
    <%--var category = $("#zd_category").val();--%>
    <%--var crown_payment = (price*<%=crown_partner_point %>).toFixed(2);--%>
    <%--var diamond_payment = (price*<%=diamond_partner_point %>).toFixed(2);--%>
    <%--var gold_payment = (price*<%=gold_partner_point %>).toFixed(2);--%>
    <%--var member_payment = (price*<%=junior_member_point %>).toFixed(2);--%>
    <%--if(category.indexOf("110")==0){//周末旅行--%>
    <%--crown_payment = 5;--%>
    <%--diamond_payment = 5;--%>
    <%--gold_payment = 5;--%>
    <%--member_payment = 0;--%>
    <%--}--%>
    <%--$("#zd_crown_partner_payment").val(crown_payment);--%>
    <%--$("#zd_diamond_partner_payment").val(diamond_payment);--%>
    <%--$("#zd_gold_partner_payment").val(gold_payment);--%>
    <%--$("#zd_junior_member_payment").val(member_payment);--%>
    <%--}--%>
    <%----%>
	
</script>
<%
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		dbHelper.freeConnection(connection);
		dbHelper.freeConnection(connection2);
	}
%>